<template>
	<!-- 最简洁，注意点会标出来的 -->
	<!-- models/AdminUser.js -->
	<!-- 数据字段：username,password（生成散列）-->
  <div class="about">
    <h1>{{id ? '编辑' : '新建'}}管理员</h1>

    <el-form label-width="120px" @submit.native.prevent="save">
      <el-form-item label="用户名">
        <el-input type="text" v-model="model.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="text" v-model="model.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" native-type="submit">保存</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
/* eslint-disable */
export default {
  props: {
    id: {}
  },
  data(){
    return {
      model: {},
      
    }
  },
  methods: {
		// http://appblog.cn/2018/07/02/ESLint%20xxx%20is%20assigned%20a%20value%20but%20never%20used%20%E7%9A%84%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/
  	async save(){
			// console.log(this.id)
			let res
      if (this.id) {
        res = await this.$http.put(`rest/admin_users/${this.id}`, this.model)
      } else {
        res = await this.$http.post('rest/admin_users', this.model)
			}
			// const res = await this.$http.post('items', this.model)
			// push要加/ 斜杠，
			this.$router.push('/admin_users/list')
			this.$message({
        type: 'success',
        message: '保存成功'
      })
		},
    async fetch(){
      const res = await this.$http.get(`rest/admin_users/${this.id}`)
      this.model = res.data
    },
    
    
  },
  created(){
    this.id && this.fetch()
  }
}
</script>